import { Hono } from "hono";
import { serve } from "@hono/node-server";
import shutdown from "./libs/shutdown/index.js";
import { parseConfig } from "ph-utils/config.js";
import { response } from "./libs/response/index.js";
import { initLogger } from "./libs/logger/index.js";

// 解析配置文件, 并解析环境变量: config.json
parseConfig(null, true);

initLogger(process.env.NODE_ENV === "production" ? "info" : "debug", "app");

const app = new Hono();

app.get("/system_monitor", async (c) => {
  return c.json(response("SUCCESS"));
});

const server = serve(
  {
    fetch: app.fetch,
    port: Number(process.env.PORT || 3000),
  },
  (info) => {
    console.log(`Listening on http://${info.address}:${info.port} ...`);
  }
);

shutdown(() => {
  server.close();
});
